package com.songdehuai.supermarket.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.songdehuai.supermarket.R;
import com.songdehuai.supermarket.adapter.MenuListAdapter;
import com.songdehuai.supermarket.adapter.ShopListAdapter;
import com.songdehuai.supermarket.supermarket.entity.SuperMarket;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class ShopListFragment extends Fragment {

    @ViewInject(R.id.menu_lv)
    RecyclerView menuLv;

    @ViewInject(R.id.shop_lv)
    RecyclerView shopLv;

    MenuListAdapter menuListAdapter;

    List<SuperMarket.ProductBean> mProductBeanList = new ArrayList<>();

    ShopListAdapter shopListAdapter;

    List<SuperMarket.ProductBean.ProductsBean> mProductsBeanList = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getContext(), R.layout.fragment_shoplist, null);
        x.view().inject(this, view);
        initViews();
        return view;
    }

    private void initViews() {

    }

    public void initMenu(List<SuperMarket.ProductBean> productBeanList) {
        this.mProductBeanList = productBeanList;
        menuLv.setLayoutManager(new LinearLayoutManager(getContext()));
        menuListAdapter = new MenuListAdapter(getContext(), productBeanList);
        menuLv.setAdapter(menuListAdapter);
        menuListAdapter.setOnItemClickLitener(new MenuListAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position) {
                initShop(mProductBeanList.get(position).getProducts());
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });

        initShop(mProductBeanList.get(0).getProducts());
    }

    private void initShop(List<SuperMarket.ProductBean.ProductsBean> productsBeanList) {
        this.mProductsBeanList = productsBeanList;
        shopLv.setLayoutManager(new LinearLayoutManager(getContext()));
        shopListAdapter = new ShopListAdapter(getContext(), mProductsBeanList);
        shopLv.setAdapter(shopListAdapter);
    }
}
